<template>
  <div class="strategy-page">
    <!-- 头部区域 -->
    <div class="strategy-header">
      <div class="header-particles">
        <div class="particle" v-for="n in 20" :key="n"></div>
      </div>

      <!-- 头部内容 -->
      <div class="strategy-header-content">
        <h2>攻略探索</h2>
        <div class="strategy-subtitle">
          <span class="subtitle-text">发现精彩</span>
          <span class="subtitle-divider">•</span>
          <span class="subtitle-text">分享旅程</span>
        </div>

        <!-- section-intro -->
        <div class="section-intro">
          <div class="intro-badge">精彩攻略</div>
          <h3>分享你的旅行故事</h3>
          <p>记录每一次精彩的探险旅程，与同行者分享宝贵经验</p>
        </div>

        <!-- 搜索和排序控件 -->
        <div class="strategy-search">
          <input type="text" v-model="searchKeyword" placeholder="搜索攻略..." @keyup.enter="searchStrategies" />

          <!-- 新增：景点筛选下拉框 -->
          <div class="filter-controls">
            <select v-model="selectedScenicSpot" @change="filterByScenery" class="filter-select">
              <option value="">全部景点</option>
              <option v-for="spot in scenicSpots" :key="spot.scenicSpotId" :value="spot.scenicSpotId">
                {{ spot.scenicAreaName || spot.scenicSpotName }}
              </option>
            </select>
          </div>

          <div class="strategy-controls">
            <div class="strategy-sort">
              <select v-model="sortType" @change="sortStrategies" class="sort-select">
                <option value="time">按时间排序</option>
                <option value="likes">按点赞量排序</option>
                <option value="collects">按收藏量排序</option>
              </select>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="strategy-container">
      <!-- 加载状态 -->
      <div v-if="loading" class="loading">
        <div class="loading-spinner"></div>
        <span>加载中...</span>
      </div>

      <!-- 空状态 -->
      <div v-else-if="notes.length === 0" class="empty-state">
        <div class="empty-icon">📝</div>
        <div>暂无攻略数据</div>
      </div>

      <!-- 攻略列表 -->
      <div v-else>
        <div class="strategy-grid">
          <div class="strategy-card" v-for="note in paginatedNotes" :key="note.strategyId"
            @click="viewDetail(note.strategyId)">
            <!-- 封面图片 -->
            <div class="strategy-img-container">
              <img class="strategy-img" :src="getCoverImage(note.strategyId)" alt="攻略封面" />
              <div class="img-overlay"></div>
            </div>

            <!-- 卡片内容 -->
            <div class="strategy-content-wrapper">
              <div class="strategy-info">
                <h3 class="strategy-title-card">{{ note.strategyName }}</h3>
                <div class="strategy-content" v-html="formatContent(note.strategyContent)"></div>
              </div>

              <!-- 关联景点信息 -->
              <div class="scenic-spot-info" v-if="getScenicSpotName(note.scenicSpotId)">
                <div class="scenic-spot-tag">
                  <i class="fas fa-map-marked-alt"></i>
                  {{ getScenicSpotName(note.scenicSpotId) }}
                </div>
              </div>

              <!-- 底部用户信息和操作按钮 -->
              <div class="strategy-footer">
                <div class="strategy-user" @click.stop="goToUserProfile(note.userId)">
                  <img class="user-avatar" :src="getUserAvatar(note.strategyId)" alt="用户头像" />
                  <span class="user-name">{{ note.userName || '未知用户' }}</span>
                </div>

                <div class="strategy-actions">
                  <button class="action-btn like-btn" :class="{ active: likeStatus[note.strategyId] }"
                    @click.stop="toggleLike(note)">
                    <svg width="16" height="16" viewBox="0 0 24 24"
                      :fill="likeStatus[note.strategyId] ? '#e74c3c' : 'none'" stroke="currentColor" stroke-width="2">
                      <path
                        d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z" />
                    </svg>
                    <span class="count">{{ likeCount[note.strategyId] || 0 }}</span>
                  </button>
                  <button class="action-btn collect-btn" :class="{ active: collectStatus[note.strategyId] }"
                    @click.stop="toggleCollect(note)">
                    <svg width="16" height="16" viewBox="0 0 24 24"
                      :fill="collectStatus[note.strategyId] ? '#f39c12' : 'none'" stroke="currentColor"
                      stroke-width="2">
                      <path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z" />
                    </svg>
                    <span class="count">{{ collectCount[note.strategyId] || 0 }}</span>
                  </button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 分页控件 -->
      <div v-if="totalPages > 1" class="pagination">
        <button class="page-btn" @click="changePage(currentPage - 1)" :disabled="currentPage === 1">
          ‹
        </button>
        <button v-for="page in getVisiblePages()" :key="page" class="page-btn" @click="changePage(page)"
          :class="{ active: currentPage === page }">
          {{ page }}
        </button>
        <button class="page-btn" @click="changePage(currentPage + 1)" :disabled="currentPage === totalPages">
          ›
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
import { ElNotification } from 'element-plus';

export default {
  name: "StrategyMain",
  data() {
    return {
      allNotes: [], // 新增：保存所有原始数据
      selectedScenicSpot: "", // 新增：选中的景点ID
      searchKeyword: "",
      notes: [],
      loading: true,
      currentPage: 1,
      pageSize: 12,
      totalCount: 0,
      sortType: 'time',
      defaultAvatar: 'https://randomuser.me/api/portraits/lego/1.jpg',
      defaultCover: 'https://images.unsplash.com/photo-1502082553048-f009c37129b9?auto=format&fit=crop&w=400&q=80',
      likeStatus: {},      // { [strategyId]: true/false }
      likeCount: {},       // { [strategyId]: 数量 }
      collectStatus: {},   // { [strategyId]: true/false }
      collectCount: {},    // { [strategyId]: 数量 }
      coverImages: {},     // 缓存封面图片
      currentUserId: null, // 当前登录用户ID
      // 新增：景点列表数据
      scenicSpots: []
    }
  },
  computed: {
    totalPages() {
      return Math.ceil(this.totalCount / this.pageSize);
    },
    // 新增：根据筛选条件过滤后的攻略
    filteredNotes() {
      let filtered = [...this.notes];

      // 按景点筛选
      if (this.selectedScenicSpot) {
        filtered = filtered.filter(note =>
          note.scenicSpotId && note.scenicSpotId.toString() === this.selectedScenicSpot.toString()
        );
      }

      return filtered;
    },

    // 新增：分页后的攻略
    paginatedNotes() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.filteredNotes.slice(start, end);
    },

    // 新增：筛选后的总页数
    totalFilteredPages() {
      return Math.ceil(this.filteredNotes.length / this.pageSize);
    },

    totalPages() {
      return Math.ceil(this.totalCount / this.pageSize);
    }
  },

  // 新增：监听筛选条件变化，重置到第一页
  watch: {
    selectedScenicSpot() {
      this.currentPage = 1;
    },
    searchKeyword() {
      this.currentPage = 1;
    }
  },


  mounted() {
    this.fetchCurrentUserId();
    this.fetchStrategies();
    this.loadScenicSpots(); // 加载景点列表
  },

  methods: {
    // 新增：加载景点列表
    async loadScenicSpots() {
      try {
        const response = await axios.get('http://localhost:8080/mw/ScenicSpotList');
        this.scenicSpots = response.data || [];
        console.log('景点列表加载成功:', this.scenicSpots.length);
      } catch (error) {
        console.error('加载景点列表失败:', error);
        this.scenicSpots = [];
      }
    },

    // 新增：根据景点ID获取景点名称
    getScenicSpotName(scenicSpotId) {
      if (!scenicSpotId || !this.scenicSpots.length) return null;
      const spot = this.scenicSpots.find(s => s.scenicSpotId === scenicSpotId);
      return spot ? spot.scenicAreaName || spot.scenicSpotName : null;
    },

    // 新增：按景点筛选
    filterByScenery() {
      this.currentPage = 1;
      // 不需要额外操作，computed属性会自动处理筛选
    },

    // 新增：清除搜索条件
    clearSearch() {
      this.searchKeyword = "";
      this.fetchStrategies();
    },

    // 新增：清除景点筛选
    clearScenicFilter() {
      this.selectedScenicSpot = "";
    },

    // 新增：清除所有筛选条件
    clearAllFilters() {
      this.searchKeyword = "";
      this.selectedScenicSpot = "";
      this.fetchStrategies();
    },




    // 跳转到用户个人主页
    goToUserProfile(userId) {
      if (userId) {
        this.$router.push(`/user/profile/${userId}`);
      }
    },

    // 获取当前登录用户ID
    async fetchCurrentUserId() {
      const loginId = localStorage.getItem('loginId');
      if (!loginId) return;

      try {
        const userRes = await axios.get(`http://localhost:8080/mw/UserByLoginId?loginId=${loginId}`);
        this.currentUserId = userRes.data.userId;
      } catch (error) {
        console.error('获取用户ID失败:', error);
      }
    },

    async fetchStrategies() {
      try {
        this.loading = true;
        const response = await axios.get('/ts/list');
        this.notes = response.data;

        // 获取每个攻略项的用户信息
        for (const note of this.notes) {
          try {
            const userRes = await axios.get(`http://localhost:8080/mw/UserById?userId=${note.userId}`);
            note.userAvatar = userRes.data.userAvatar; // 假设返回的用户信息中包含 userAvatar
          } catch (error) {
            console.error('获取用户信息失败:', error);
            note.userAvatar = this.defaultAvatar;
          }
        }

        // 获取攻略总数
        const countResponse = await axios.get('/ts/count');
        this.totalCount = countResponse.data;

        // 预加载封面图片
        await this.preloadCoverImages();

        // 获取点赞和收藏状态
        await this.fetchLikeAndCollectStatus();

        // 根据当前排序方式排序
        this.sortStrategies();

      } catch (error) {
        console.error('获取攻略列表失败:', error);
      } finally {
        this.loading = false;
      }
    },

    // 获取点赞和收藏状态
    async fetchLikeAndCollectStatus() {
      if (!this.currentUserId) return;

      for (const note of this.notes) {
        // 获取点赞状态
        try {
          const likeRes = await axios.get('http://localhost:8080/strlike/checkLike', {
            params: {
              userId: this.currentUserId,
              strategyId: note.strategyId
            }
          });
          this.likeStatus[note.strategyId] = !!likeRes.data;

          const likeCountRes = await axios.get('http://localhost:8080/strlike/countByStrategyId', {
            params: { strategyId: note.strategyId }
          });
          this.likeCount[note.strategyId] = likeCountRes.data || 0;
        } catch (error) {
          console.error('获取点赞状态失败:', error);
        }

        // 获取收藏状态
        try {
          const collectRes = await axios.get('http://localhost:8080/strategyCollect/checkFavorite', {
            params: {
              userId: this.currentUserId,
              strategyId: note.strategyId
            }
          });
          this.collectStatus[note.strategyId] = !!collectRes.data;

          const collectCountRes = await axios.get('http://localhost:8080/strategyCollect/countByStrategyId', {
            params: { strategyId: note.strategyId }
          });
          this.collectCount[note.strategyId] = collectCountRes.data || 0;
        } catch (error) {
          console.error('获取收藏状态失败:', error);
        }
      }
    },

    // 点赞/取消点赞
    async toggleLike(note) {
      if (!this.currentUserId) {
        ElNotification.warning('请先登录才能点赞');
        return;
      }

      const strategyId = note.strategyId;
      try {
        if (this.likeStatus[strategyId]) {
          // 取消点赞
          await axios.delete('http://localhost:8080/strlike/deleteByUserAndStrategy', {
            params: {
              userId: this.currentUserId,
              strategyId
            }
          });
          this.likeStatus[strategyId] = false;
          this.likeCount[strategyId] = Math.max((this.likeCount[strategyId] || 0) - 1, 0);
        } else {
          // 点赞
          await axios.post('http://localhost:8080/strlike/insert', {
            userId: this.currentUserId,
            strategyId,
            likeTime: new Date().toISOString()
          });
          this.likeStatus[strategyId] = true;
          this.likeCount[strategyId] = (this.likeCount[strategyId] || 0) + 1;
        }
      } catch (error) {
        ElNotification.error('操作失败: ' + error.message);
      }
    },

    // 收藏/取消收藏
    async toggleCollect(note) {
      if (!this.currentUserId) {
        ElNotification.warning('请先登录才能收藏');
        return;
      }

      const strategyId = note.strategyId;
      const currentCount = this.collectCount[strategyId] || 0;

      try {
        if (this.collectStatus[strategyId]) {
          // 取消收藏
          await axios.delete('http://localhost:8080/strategyCollect/deleteByUserAndStrategy', {
            params: {
              userId: this.currentUserId,
              strategyId
            }
          });
          this.collectStatus[strategyId] = false;
          this.collectCount[strategyId] = Math.max(currentCount - 1, 0);
        } else {
          // 收藏
          await axios.post('http://localhost:8080/strategyCollect/insert', {
            userId: this.currentUserId,
            strategyId,
            favoriteTime: new Date().toISOString()
          });
          this.collectStatus[strategyId] = true;
          this.collectCount[strategyId] = currentCount + 1;
        }
      } catch (error) {
        ElNotification.error('操作失败: ' + error.message);
      }
    },

    // 预加载封面图片
    // 预加载封面图片和用户头像
    async preloadCoverImages() {
      for (const note of this.notes) {
        try {
          const response = await axios.get(`/ts/detail/${note.strategyId}`);
          const data = response.data;

          // 缓存封面图片
          if (data.images && data.images.length > 0) {
            this.coverImages[note.strategyId] = {
              cover: data.images[0].strategyImageLink,
              userAvatar: data.detail.userAvatar
            };
          } else {
            // 如果没有图片，也缓存用户头像
            this.coverImages[note.strategyId] = {
              cover: this.defaultCover,
              userAvatar: data.detail.userAvatar
            };
          }
        } catch (error) {
          console.error('获取攻略详情失败:', error);
          this.coverImages[note.strategyId] = {
            cover: this.defaultCover,
            userAvatar: this.defaultAvatar
          };
        }
      }
    },

    // 获取封面图片
    getCoverImage(strategyId) {
      return this.coverImages[strategyId]?.cover || this.defaultCover;
    },

    // 处理用户头像
    // 处理用户头像
    getUserAvatar(strategyId) {
      // 如果已经缓存了头像，直接返回
      if (this.coverImages[strategyId] && this.coverImages[strategyId].userAvatar) {
        return this.coverImages[strategyId].userAvatar;
      }

      // 否则返回默认头像
      return this.defaultAvatar;
    },

    // 格式化内容
    formatContent(content) {
      if (!content) return '';
      return content.length > 30 ? content.substring(0, 30) + '...' : content;
    },

    // 排序功能
    sortStrategies() {
      if (!this.notes || this.notes.length === 0) return;

      const sortedNotes = [...this.notes].sort((a, b) => {
        switch (this.sortType) {
          case 'likes':
            const aLikes = this.likeCount[a.strategyId] || 0;
            const bLikes = this.likeCount[b.strategyId] || 0;
            return bLikes - aLikes;
          case 'collects':
            const aCollects = this.collectCount[a.strategyId] || 0;
            const bCollects = this.collectCount[b.strategyId] || 0;
            return bCollects - aCollects;
          case 'time':
          default:
            return b.strategyId - a.strategyId;
        }
      });

      this.notes = sortedNotes;
    },

    // 搜索攻略
    async searchStrategies() {
      if (!this.searchKeyword.trim()) {
        this.fetchStrategies();
        return;
      }

      try {
        this.loading = true;
        const response = await axios.get('/ts/search', {
          params: { name: this.searchKeyword }
        });

        this.notes = response.data;
        this.totalCount = this.notes.length;
        this.currentPage = 1;

        // 更新点赞收藏状态
        await this.fetchLikeAndCollectStatus();

        // 根据当前排序方式排序
        this.sortStrategies();

      } catch (error) {
        console.error('搜索攻略失败:', error);
      } finally {
        this.loading = false;
      }
    },

    // 查看详情
    viewDetail(strategyId) {
      this.$router.push({
        name: 'UStrategyDetail',
        params: { id: strategyId }
      });
    },

    // 分页切换
    changePage(page) {
      if (page >= 1 && page <= this.totalPages) {
        this.currentPage = page;
        this.fetchStrategies();
      }
    },

    // 获取可见的页码
    getVisiblePages() {
      const total = this.totalPages;
      const current = this.currentPage;
      const delta = 2;

      let start = Math.max(1, current - delta);
      let end = Math.min(total, current + delta);

      if (end - start < 2 * delta) {
        if (start === 1) {
          end = Math.min(total, start + 2 * delta);
        } else {
          start = Math.max(1, end - 2 * delta);
        }
      }

      const pages = [];
      for (let i = start; i <= end; i++) {
        pages.push(i);
      }
      return pages;
    }
  }
}
</script>

<style scoped>
/* 景点筛选下拉框美化，与其他内容风格一致 */
.filter-controls {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 22px;
  gap: 16px;
  z-index: 2;
}

/* 下拉框样式仿照 .sort-select */
.filter-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.13);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  padding: 10px 44px 10px 20px; /* 为下拉箭头留空间 */
  font-size: 1rem;
  color: #fff;
  cursor: pointer;
  outline: none;
  transition: all 0.3s cubic-bezier(.4,2,.5,1);
  min-width: 200px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.12);
  /* 自定义下拉箭头 */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.85)' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.filter-select option {
  background: #333;
  color: #fff;
  font-size: 1rem;
}

.filter-select:hover,
.filter-select:focus {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 25px rgba(0,0,0,0.13);
  transform: translateY(-2px);
}

/* 响应式适配 */
@media (max-width: 700px) {
  .filter-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 10px;
  }
  .filter-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
}

/* 整体页面样式 - 固定背景覆盖整个页面 */
.strategy-page {
  padding: 0;
  margin: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* 确保背景图片覆盖整个页面 */
.strategy-page::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(135deg, rgba(74, 144, 226, 0.8), rgba(107, 91, 149, 0.8)),
    url('https://images.unsplash.com/photo-1506905925346-21bda4d32df4?ixlib=rb-4.0.3&auto=format&fit=crop&w=2000&q=80') center/cover;
  z-index: 0;
  pointer-events: none;
}

/* 确保所有内容在背景之上 */
.strategy-page>* {
  position: relative;
  z-index: 1;
}

/* 头部样式 - 减少高度，不占满屏幕 */
.strategy-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: white;
  text-align: center;
  position: relative;
  width: 100%;
  padding: 120px 20px 20px;
  /* 减少padding */
  overflow: hidden;
  background: none;
  min-height: auto;
  /* 移除固定高度 */
}

/* 粒子效果容器 */
.header-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 1;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 50%;
  animation: float 6s ease-in-out infinite;
}

.particle:nth-child(odd) {
  animation-delay: -2s;
}

.particle:nth-child(even) {
  animation-delay: -4s;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0px) rotate(0deg);
    opacity: 0;
  }

  50% {
    transform: translateY(-100px) rotate(180deg);
    opacity: 1;
  }
}

/* 确保头部内容在粒子之上 */
.strategy-header-content {
  position: relative;
  z-index: 2;
  margin-bottom: 30px;
  /* 减少底部边距 */
  max-width: 800px;
  width: 100%;
}

.strategy-header h2 {
  font-size: 3rem;
  /* 减小字体 */
  font-weight: 300;
  letter-spacing: 6px;
  /* 减少字间距 */
  margin: 0;
  text-transform: uppercase;
  margin-bottom: 15px;
  /* 减少底部边距 */
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.strategy-subtitle {
  font-size: 1.1rem;
  /* 稍微减小字体 */
  font-weight: 300;
  letter-spacing: 2px;
  margin-bottom: 25px;
  /* 减少底部边距 */
  opacity: 0.9;
}

.subtitle-text {
  display: inline-block;
}

.subtitle-divider {
  margin: 0 15px;
  opacity: 0.7;
}

/* section-intro样式 */
.section-intro {
  margin-top: 15px;
  /* 减少顶部边距 */
  padding: 0 20px;
  margin-bottom: 25px;
  /* 减少底部边距 */
}

.intro-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  padding: 6px 16px;
  /* 减少padding */
  border-radius: 20px;
  font-size: 0.85rem;
  /* 稍微减小字体 */
  font-weight: 500;
  letter-spacing: 1px;
  margin-bottom: 15px;
  /* 减少底部边距 */
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
}

.section-intro h3 {
  font-size: 1.6rem;
  /* 减小字体 */
  font-weight: 400;
  margin: 0 0 10px 0;
  /* 减少底部边距 */
  color: white;
  letter-spacing: 2px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

.section-intro p {
  font-size: 1rem;
  /* 稍微减小字体 */
  color: rgba(255, 255, 255, 0.9);
  margin: 0 0 15px 0;
  /* 减少底部边距 */
  line-height: 1.6;
  letter-spacing: 1px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
}

/* 搜索和控制区域 */
.strategy-search {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  /* 减少底部边距 */
  flex-wrap: wrap;
  justify-content: center;
  z-index: 2;
}

.strategy-search input {
  width: 320px;
  padding: 10px 20px;
  /* 减少padding */
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1rem;
  /* 稍微减小字体 */
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  outline: none;
  min-width: 300px;
}

.strategy-search input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}

.strategy-search input:focus {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.strategy-controls {
  display: flex;
  align-items: center;
}

.strategy-sort {
  position: relative;
}

.sort-select {
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  padding: 10px 20px;
  /* 减少padding */
  font-size: 1rem;
  /* 稍微减小字体 */
  color: white;
  cursor: pointer;
  outline: none;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  min-width: 200px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.8)' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center Stormtroopercenter;
  padding-right: 45px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.sort-select option {
  background: #333;
  color: white;
}

.sort-select:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.sort-select:focus {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

/* 内容区域样式 - 直接跟在头部后面 */
.strategy-container {
  position: relative;
  /* 改为相对定位 */
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px 60px 40px;
  /* 减少顶部padding */
  background: none;
  min-height: auto;
  z-index: 2;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: rgba(255, 255, 255, 0.9);
  background: none;
  width: 100%;
  box-sizing: border-box;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid #ffffff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: rgba(255, 255, 255, 0.9);
  background: none;
}

.empty-icon {
  font-size: 3em;
  margin-bottom: 16px;
  opacity: 0.6;
}

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  width: 100%;
  margin-bottom: 40px;
}

@media (max-width: 1200px) {
  .strategy-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .strategy-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .strategy-grid {
    grid-template-columns: 1fr;
  }
}

/* Animation definition for card rising effect */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(40px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.strategy-card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  position: relative;
  animation: fadeInUp 0.8s ease-out forwards;
  opacity: 0;
}

/* Staggered delays for each card */
.strategy-grid .strategy-card:nth-child(1) {
  animation-delay: 0.1s;
}

.strategy-grid .strategy-card:nth-child(2) {
  animation-delay: 0.2s;
}

.strategy-grid .strategy-card:nth-child(3) {
  animation-delay: 0.3s;
}

.strategy-grid .strategy-card:nth-child(4) {
  animation-delay: 0.4s;
}

.strategy-grid .strategy-card:nth-child(5) {
  animation-delay: 0.5s;
}

.strategy-grid .strategy-card:nth-child(6) {
  animation-delay: 0.6s;
}

.strategy-grid .strategy-card:nth-child(7) {
  animation-delay: 0.7s;
}

.strategy-grid .strategy-card:nth-child(8) {
  animation-delay: 0.8s;
}

.strategy-grid .strategy-card:nth-child(9) {
  animation-delay: 0.9s;
}

.strategy-grid .strategy-card:nth-child(10) {
  animation-delay: 1.0s;
}

.strategy-grid .strategy-card:nth-child(11) {
  animation-delay: 1.1s;
}

.strategy-grid .strategy-card:nth-child(12) {
  animation-delay: 1.2s;
}

.strategy-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  background: rgba(255, 255, 255, 0.98);
}

.strategy-img-container {
  position: relative;
  width: 100%;
  padding-bottom: 60%;
  overflow: hidden;
}

.strategy-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.strategy-card:hover .strategy-img {
  transform: scale(1.05);
}

.img-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.3), transparent);
  pointer-events: none;
}

.strategy-content-wrapper {
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}

.strategy-info {
  flex: 1;
  margin-bottom: 12px;
}

.strategy-title-card {
  font-size: 18px;
  font-weight: 600;
  color: #262626;
  margin: 0 0 8px 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.strategy-content {
  font-size: 14px;
  color: #737373;
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scenic-spot-info {
  margin: 12px 0;
}

.scenic-spot-tag {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, #66eaaf 0%, #6a856a 100%);
  color: white;
  padding: 6px 12px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(102, 234, 175, 0.3);
}

.scenic-spot-tag i {
  margin-right: 6px;
  font-size: 11px;
}

.strategy-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #f0f0f0;
}

.strategy-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.strategy-user:hover {
  opacity: 0.7;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #e0e0e0;
}

.user-name {
  font-size: 14px;
  color: #262626;
  font-weight: 500;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-actions {
  display: flex;
  gap: 16px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s;
  color: #737373;
}

.action-btn:hover {
  background: #f5f5f5;
  transform: scale(1.05);
}

.action-btn.active.like-btn {
  color: #e74c3c;
}

.action-btn.active.collect-btn {
  color: #f39c12;
}

.action-btn .count {
  font-size: 13px;
  font-weight: 600;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 40px 0;
  gap: 8px;
  background: none;
  padding: 20px 0;
}

.page-btn {
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  cursor: pointer;
  color: #262626;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.page-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(255, 255, 255, 0.6);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.page-btn.active {
  background: rgba(255, 255, 255, 0.95);
  color: #0095f6;
  border-color: rgba(255, 255, 255, 0.6);
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .strategy-header {
    padding: 30px 15px 20px;
    /* 进一步减少移动端padding */
  }

  .strategy-header h2 {
    font-size: 2.2rem;
    /* 减小移动端字体 */
    letter-spacing: 3px;
  }

  .section-intro h3 {
    font-size: 1.3rem;
  }

  .strategy-search {
    flex-direction: column;
    width: 100%;
    padding: 0 20px;
    gap: 12px;
    margin-bottom: 15px;
    /* 减少移动端底部边距 */
  }

  .strategy-search input,
  .sort-select {
    width: 100%;
    max-width: 300px;
    min-width: 250px;
  }

  .strategy-container {
    padding: 15px 16px;
    /* 减少移动端padding */
  }

  .strategy-grid {
    gap: 16px;
  }
}

@media (max-width: 480px) {
  .strategy-header {
    padding: 25px 15px 15px;
    /* 进一步减少小屏幕padding */
  }

  .strategy-header h2 {
    font-size: 1.8rem;
    /* 进一步减小字体 */
    letter-spacing: 2px;
  }

  .strategy-subtitle {
    font-size: 0.95rem;
  }

  .strategy-search input,
  .sort-select {
    min-width: 200px;
  }

  .strategy-content-wrapper {
    padding: 16px;
    min-height: 120px;
  }
}

/* 保证搜索攻略输入框、景点筛选下拉框、排序下拉框高度和竖直方向完全一致 */

.strategy-search {
  display: flex;
  align-items: center;     /* 垂直居中 */
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 2;
}

/* 统一高度变量 */
:root {
  --search-bar-height: 44px;
}

/* 搜索输入框 */
.strategy-search input {
  height: var(--search-bar-height);
  line-height: var(--search-bar-height);
  width: 320px;
  padding: 100 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 1rem;
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  outline: none;
  min-width: 200px;
  max-width: 330px;
  margin: 0; /* 去除意外的外边距 */
  display: block;
}

/* 景点筛选按钮(下拉框) */
.filter-select {
  appearance: none;
  height: var(--search-bar-height);
  line-height: var(--search-bar-height);
  padding: 100 44px 0 20px; /* 上下padding为0，左右一致，右侧为下拉箭头留空间 */
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.13);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  color: #fff;
  cursor: pointer;
  outline: none;
  transition: all 0.3s cubic-bezier(.4,2,.5,1);
  min-width: 200px;
  max-width: 260px;
  box-sizing: border-box;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0,0,0,0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.85)' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  margin: 0; /* 去除意外的外边距 */
  display: block;
}

/* 排序按钮(下拉框) */
.sort-select {
  appearance: none;
  height: var(--search-bar-height);
  line-height: var(--search-bar-height);
  padding: 100 45px 0 20px;
  font-size: 1rem;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 25px;
  color: white;
  cursor: pointer;
  outline: none;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  min-width: 200px;
  max-width: 260px;
  box-sizing: border-box;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.8)' stroke-width='2'%3E%3Cpolyline points='6,9 12,15 18,9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 15px center;
  margin: 0; /* 去除意外的外边距 */
  display: block;
}

/* 控制外层布局，防止高度受父div影响 */
.filter-controls,
.strategy-controls {
  display: flex;
  align-items: center;
  height: var(--search-bar-height);
  margin: 0;
  padding: 0;
}

/* 响应式适配 */
@media (max-width: 700px) {
  .strategy-search {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .strategy-search input,
  .filter-select,
  .sort-select {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .filter-controls,
  .strategy-controls {
    width: 100%;
    height: var(--search-bar-height);
  }
}

</style>